﻿using System.Collections.Generic;
using Bots.DungeonBuddy.Attributes;
using Bots.DungeonBuddy.Helpers;
using Styx;
using Styx.Logic;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using TreeSharp;
using System.Linq;
namespace Bots.DungeonBuddy.Dungeons.Classic
{
    public class ShadowfangKeep : Dungeon
    {
        #region Overrides of Dungeon

        /// <summary> The mapid of this dungeon. </summary>
        /// <value>The map identifier.</value>
        public override uint DungeonId
        {
            get { return 8; }
        }

        public override WoWPoint Entrance { get { return new WoWPoint(-233.2333, 1571, 76.88484); } }

        public override void WeighTargetsFilter(List<Targeting.TargetPriority> units)
        {
            foreach (var t in units)
            {
                var prioObject = t.Object;

                //Trash
                if (prioObject.Entry == 47137)
                {
                    t.Score += 400;
                }

                //Baron Silverlain's Summoned adds need to die first
                if (prioObject.Entry == 50857 || prioObject.Entry == 50869 || prioObject.Entry == 50834 || prioObject.Entry == 50851)
                {
                    t.Score += 1000;
                }

                if (prioObject.Entry == 50561)
                {
                    t.Score += 1000;
                }
            }
        }

        #endregion

        #region Encounter Handlers


        [EncounterHandler(47138, Mode = CallBehaviorMode.Proximity)]
        public Composite PustulantMonstrosity()
        {
            return ScriptHelpers.CreateClearArea(() => new WoWPoint(-91.75407,2128.595,144.9211), 50, u => u.Entry == 47138);
        }

        [EncounterHandler(46962, "Baron Ashbury")]
        public Composite BaronAshburyFight()
        {
            //No scripting currently needed for Reg mode, will need it for Heroic
            return
                new PrioritySelector();
        }

        [EncounterHandler(3887, "Baron Silverlaine")]
        public Composite BaronSilverlaineFight()
        {
            //No scripting currently needed for Reg mode, will need it for Heroic. Targeting is done in TargetFilters Above
            return
                new PrioritySelector();
        }

        [EncounterHandler(4278, "Commander Springvale", Mode = CallBehaviorMode.Proximity)]
        public Composite CommanderSpringvaleFight()
        {
            return ScriptHelpers.CreateRunAwayFromBad(rx => true, 40, 50503);
        }

        [EncounterHandler(46963, "Lord Walden")]//3887
        public Composite LordWaldenFight()
        {
           //This function still needs to be scripted but its the only thing needed here so when it is scripted will just automatically work
            return
                ScriptHelpers.CreateSpreadOutLogic(ctx => true, 5);
        }

        [EncounterHandler(46964, "Lord Godfrey")]
        public Composite LordGodfreyFight()
        {

            //var unit = ObjectManager.GetObjectsOfType<WoWUnit>().FirstOrDefault(x => x.Entry == 46946);
           
            //return ScriptHelpers.GetBehindUnit(r => unit != null && unit.CastingSpellId == 93520, () => unit);
            //return ScriptHelpers.GetBehindUnit(r => ScriptHelpers.CurrentBoss.CastingSpellId == 93520,() => ScriptHelpers.CurrentBoss);
            WoWUnit boss = null;
            return
                new PrioritySelector(ctx => boss = ctx as WoWUnit,  
                    ScriptHelpers.GetBehindUnit(r => boss.CastingSpellId == 93520 && !boss.IsPlayerBehind, () => boss)
                    , new Decorator(r => boss.CastingSpellId != 93520, ScriptHelpers.CreateTankUnitAtLocation(() => new WoWPoint(-98.13088, 2143.893, 144.921), 5f)));
        }


        #endregion
    }
}
